package com.haida.translation_web.controller;

import com.haida.translation_web.aop.ann.LimitAccess;
import com.haida.translation_web.pojo.TransRecordEntity;
import com.haida.translation_web.pojo.respone.PageUtils;
import com.haida.translation_web.pojo.respone.R;
import com.haida.translation_web.pojo.respone.ResultVO;
import com.haida.translation_web.service.TransRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @Author LHJ_Jack
 * @Date 2021/05/29 星期六 20:46
 */
@RestController
@RequestMapping("trans")
public class TransController {

    @Autowired
    TransRecordService transRecordService;
    @PostMapping("/word")
    @LimitAccess()
    public R trans(@RequestBody TransRecordEntity entity) {
        return transRecordService.trans(entity);
    }



    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = transRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        TransRecordEntity transRecord = transRecordService.getById(id);

        return R.ok().put("transRecord", transRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TransRecordEntity transRecord){
        transRecordService.save(transRecord);

        return R.ok("评分成功。");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TransRecordEntity transRecord){
        transRecordService.updateById(transRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        transRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}

